<template>
  <div>
    <el-container class="main">
      <el-aside width="auto">
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          style="height: 100%"
          :collapse="isCollapse"
          router
        >
          <el-menu-item index="/home">
            <i class="iconfont icon-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/home/kblist">
            <i class="el-icon-menu"></i>
            <span slot="title">口碑列表</span>
          </el-menu-item>
          <el-menu-item index="/home/kbadd">
            <i class="el-icon-folder-add"></i>
            <span slot="title">添加口碑</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
          <div class="header-left">
            <i
              class="btn"
              :class="{
                'el-icon-s-fold': !isCollapse,
                'el-icon-s-unfold': isCollapse,
              }"
              @click="isCollapse = !isCollapse"
            ></i>
            北大青鸟中博软件学院
          </div>
          <div class="header-right">
            <el-dropdown>
              <span class="el-dropdown-link">
                欢迎您：{{username}} <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>基本设置</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item><span @click="logout">退出登录</span></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      username: ""
    };
  },
  created() {
     this.username = localStorage.getItem('username')
  },
  methods: {
    logout() {
      window.localStorage.removeItem('token');
      window.localStorage.removeItem('username');
      this.$message("退出成功！")
      this.$router.push('/login')
    }
  },
};
</script>

<style lang="scss" scoped>
@import url("http://at.alicdn.com/t/font_2564571_9bbpn8iitvl.css");

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }


.header {
  display: flex;
  justify-content: space-between;
}
.header-left {
  display: flex;
  align-items: center;
}
.btn {
  font-size: 20px;
  cursor: pointer;
}
.main {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

.icon-home {
  margin: 0 6px;
}
</style>